﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SCS.Common.Models;

namespace SCS.DAL
{
    public class ClassRepository : Repository<Class>, IClassRepository
    {
        public ClassRepository(SCSContext _context)
            : base(_context)
        { }


        public int GetCount()
        {
            return DBSet.Count();
        }

        /// <summary>
        /// Get Search Count
        /// </summary>
        /// <param name="searchStringID">text search</param>
        /// <returns>count of search result</returns>
        public int GetSearchCount(string searchStringID)
        {
            return DBSet.Where(s => s.classID.ToString().Contains(searchStringID)).Count();
        }

        /// <summary>
        /// Get Class Paging
        /// </summary>
        /// <param name="pageNumber">Number of page</param>
        /// <param name="pageSize">Size of page</param>
        /// <returns>List of Class</returns>
        public IEnumerable<Class> GetClassPaging(int pageNumber, int pageSize)
        {
            return DBSet.OrderBy(x => x.classID)
          .Skip((pageNumber - 1) * pageSize)
          .Take(pageSize)
          .ToList();
        }

        /// <summary>
        /// Search Class to Paging
        /// </summary>
        /// <param name="pageNumber">Number of page</param>
        /// <param name="pageSize">Size of page</param>
        /// <param name="searchStringID">text search</param>
        /// <returns>List Class</returns>
        public IEnumerable<Class> SearchClassPaging(int pageNumber, int pageSize, string searchStringID)
        {
            return DBSet.Where(s => s.classID.ToString().Contains(searchStringID)).OrderBy(x => x.classID)
         .Skip((pageNumber - 1) * pageSize)
         .Take(pageSize)
         .ToList();
        }
    }
}